import com.nineclock.activiti.ActivitiDemoApplication;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.task.Task;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@SpringBootTest(classes = ActivitiDemoApplication.class)
@RunWith(SpringRunner.class)
public class ActivitiDemoTest3 {
    @Autowired
    private RepositoryService repositoryService;
    
    @Test
    public void testDeployment(){
        Deployment deployment = repositoryService.createDeployment()
                .name("liu")
                .addClasspathResource("first.bpmn")
                .deploy();
    }

    @Autowired
    private RuntimeService runtimeService;

    @Test
    public void testStart(){
        //根据id启动任务
        runtimeService.startProcessInstanceById("myProcess_1:1:2504");
        //根据key 启动任务
        //runtimeService.startProcessInstanceByKey("myProcess_1");
    }

    @Autowired
    private TaskService taskService;

    @Test
    public void testComplete(){
        taskService.complete("5006");
    }

    /**
     * 查询指定用户任务
     */
    @Test
    public void rejectTask(){
        List<Task> taskList = taskService.createTaskQuery().processDefinitionId("myProcess_1:2:10004").taskAssignee("itheima").list();

        for (Task task : taskList) {
            System.out.println(task);
        }
    }

    @Test
    public void testDeleteTask(){
        //根据流程 key查询流程
        ProcessDefinition definition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("myProcess_1").singleResult();
        //根据 id删除 流程
        repositoryService.deleteDeployment(definition.getDeploymentId());
    }
}